package com.yq.day74.danli.v3;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/04 11:16
 * 单例设计模式的实现  线程安全 两次判断 同步代码块
 */
public class Singleton3 {

    //自身全局变量 先不赋值
    private static Singleton3 instance;

    //私有化构造方法
    private Singleton3() {
    }


    public static  Singleton3 getInstance() {
        //一次判断线程不安全
        if (instance ==null){
            synchronized (Singleton3.class){
                //二次判断
                if (instance ==null){
                    instance = new Singleton3();
                }
            }
        }
        return instance;
    }

}



